import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/config/lf_route.dart';
import 'package:largefriends/pages/lf_delete_account/lf_delete_account_logic.dart';
import 'package:largefriends/pages/lf_forget_password/lf_forget_password_logic.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:largefriends/res/lf_text_style.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/widgets/category_widget.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';
import 'package:largefriends/widgets/lf_button.dart';
import 'package:largefriends/widgets/lf_text_filed.dart';

class LfDeleteAccountPage extends StatefulWidget {
  const LfDeleteAccountPage({super.key});

  @override
  State<LfDeleteAccountPage> createState() => _LfDeleteAccountPageState();
}

class _LfDeleteAccountPageState extends State<LfDeleteAccountPage> {
  final logic = Get.put(LfDeleteAccountLogic());
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: lfAppBar(
            title: strDeleteAccount.tr,
            leadingCallback: () {
              Get.back();
            },
          ),
          body: Padding(
            padding: EdgeInsets.symmetric(horizontal: 15.w),
            child: SingleChildScrollView(
              child: Column(children: [
                LfCategoryWidget(
                    title: strYourPassword.tr,
                    child: Column(
                      children: [
                        10.h.sbh,
                        LfTextFiled(
                          textEditingController: logic.passwordController,
                          focusNode: logic.passwordNode,
                          isPassword: true,
                          hintText: strEnterYourPassword.tr,
                          inputFormatters: [
                            LengthLimitingTextInputFormatter(16),
                            FilteringTextInputFormatter.deny(RegExp('[ ]')),
                          ],
                          onChanged: (value) {
                            logic.password.value = value.trim();
                          },
                        ),
                        10.h.sbh,
                        Align(
                          alignment: Alignment.centerLeft,
                          child: InkWell(
                            onTap: () {
                              toForgetPassword(
                                  email:
                                      logic.authService.currentAccount!.email ??
                                          "");
                            },
                            child: Text(
                              strForgotPassword.tr,
                              style: lfTextStyle(
                                  sp: 15.sp,
                                  decoration: TextDecoration.underline),
                            ),
                          ),
                        ),
                        30.h.sbh,
                        Text(
                          strDeleteAccountTip.tr,
                          style: lfTextStyle(
                            sp: 15.sp,
                            fontFamily: fontRegular,
                          ),
                        ),
                        20.h.sbh,
                        Text(
                          strDeleteOrHiddenTip.tr,
                          style:
                              lfTextStyle(sp: 15.sp, fontFamily: fontRegular),
                        ),
                        20.h.sbh,
                        Obx(
                          () => LfButton(
                            enabled: logic.enableDelete,
                            text: strConfirm.tr,
                            onPress: () {
                              logic.deleteAccount();
                            },
                          ),
                        ),
                        20.h.sbh,
                        LfButton(
                          enabled: true,
                          text: strBackToMyProfile.tr,
                          onPress: () {
                            Get.until((route) =>
                                Get.currentRoute == LFRoute.pathHome);
                          },
                        ),
                      ],
                    ))
              ]),
            ),
          ),
        ),
        onWillPop: () async {
          Get.back();
          return false;
        });
  }
}
